#include "stdio.h"
#include "string.h"

#if 0
#define BITs	256

unsigned char BitArray[BITs/8];

int GetBitVal(int bit_no)
{
	int byte_idx = bit_no/8;
	int bit_idx_in_byte = bit_no%8;
	unsigned char byte = BitArray[byte_idx];
	if(byte & (0x01<<bit_idx_in_byte))
		return 1;
	else 
		return 0;
}


void SetBit(int bit_no)
{
	int byte_idx = bit_no/8;
	int bit_idx_in_byte = bit_no%8;
	BitArray[byte_idx] |= (0x01<<bit_idx_in_byte);
}

void Mark(int bit_no)
{
	SetBit(bit_no);
}

int ColumnUse(int bit_no)
{
	GetBitVal(bit_no);
}
#endif


#if 0
#define Col_A   0
#define Col_B   1
#define Col_C   2
#define Col_D   3
#define Col_E   4
#define Col_F   5
#define Col_G   6
#define Col_H   7
#define Col_I   8
#define Col_J   9
#define Col_K   10
#define Col_L   11
#define Col_M   12
#define Col_N   13
#define Col_O   14
#define Col_P   15
#define Col_Q   16
#define Col_R   17
#define Col_S   18
#define Col_T   19
#define Col_U   20
#define Col_V   21
#define Col_W   22
#define Col_X   23
#define Col_Y   24
#define Col_Z   25

#define Col_AA  26
#define Col_AB  27
#define Col_AC  28
#define Col_AD  29
#define Col_AE  30
#define Col_AF  31
#define Col_AG  32
#define Col_AH  33
#define Col_AI  34
#define Col_AJ  35
#define Col_AK  36
#define Col_AL  37
#define Col_AM  38
#define Col_AN  39
#define Col_AO  40
#define Col_AP  41
#define Col_AQ  42
#define Col_AR  43
#define Col_AS  44
#define Col_AT  45
#define Col_AU  46
#define Col_AV  47
#define Col_AW  48
#define Col_AX  49
#define Col_AY  50
#define Col_AZ  51

#define Col_BA  52
#define Col_BB  53
#define Col_BC  54
#define Col_BD  55
#define Col_BE  56
#define Col_BF  57
#define Col_BG  58
#define Col_BH  59
#define Col_BI  60
#define Col_BJ  61
#define Col_BK  62
#define Col_BL  63
#define Col_BM  64
#define Col_BN  65
#define Col_BO  66
#endif


//Excel列序号: A,B,...,Z,AA,AB,...,AZ,BA,BB,...,BZ ... ...
//转换为整数
int letter_to_int(char* column_idx)
{
	int col_no = 0;
	int len=strlen(column_idx);
	switch(len)
	{
		case 1:
			if(column_idx[0] > 'Z' || column_idx[0] < 'A') { return -1; }
			col_no = column_idx[0]-'A';
			break;
		case 2:
			if((column_idx[0] > 'Z' || column_idx[0] < 'A') || 
			   (column_idx[1] > 'Z' || column_idx[1] < 'A') ) 
			{ 
				return -1; 
			}
			col_no = (column_idx[0]-'A'+1)*26 + column_idx[1]-'A';
			break;
		default:
			break;
	}
	//printf("letter[%s] --> integer[%d]\n", column_idx, col_no);
	return col_no;
}

int GetBitVal(unsigned char *BitArray, int bit_no)
{
	int byte_idx = bit_no/8;
	int bit_idx_in_byte = bit_no%8;
	unsigned char byte = BitArray[byte_idx];
	if(byte & (0x01<<bit_idx_in_byte))
		return 1;
	else 
		return 0;
}


void SetBit(unsigned char *BitArray, int bit_no)
{
	int byte_idx = bit_no/8;
	int bit_idx_in_byte = bit_no%8;
	BitArray[byte_idx] |= (0x01<<bit_idx_in_byte);
}

void Mark(unsigned char *BitArray, int bit_no)
{
	SetBit(BitArray, bit_no);
}

int ColumnUse(unsigned char *BitArray, int bit_no)
{
	GetBitVal(BitArray, bit_no);
}